package cn.fzc.example.redis.controller;

import cn.fzc.example.redis.distributedlock.manager.LuaLockRedisLockManager;
import cn.fzc.example.redis.distributedlock.manager.SimpleRedisLockManager;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.concurrent.ThreadLocalRandom;

/**
 * @Author: fu.zc
 * @Date: 2020/8/5 14:01
 * @Description:
 */
@RestController
public class RedisController {

    @Autowired
    private SimpleRedisLockManager simpleRedisLockManager;
    @Autowired
    private LuaLockRedisLockManager luaLockRedisLockManager;


    @GetMapping("/distributeLock")
    public void distributeLock() {
        simpleRedisLockManager.lockCallBack("distribute" + ThreadLocalRandom.current().nextInt(1000), () -> System.out.println("lockCallBack"));
    }

    @GetMapping("/luaDistributeLock")
    public void luaDistributeLock() {
        luaLockRedisLockManager.lockCallBack("distribute" + ThreadLocalRandom.current().nextInt(1000), () -> System.out.println("luaDistributeLock"));
    }

}
